package com.meilingcloud.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meilingcloud.common.constant.Constants;
import com.meilingcloud.system.domain.SysLabelType;
import com.meilingcloud.system.mapper.SysLabelTypeMapper;
import com.meilingcloud.system.service.ISysLabelTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 标签类型 Service业务层处理
 *
 * @author chenl
 * @date 2021-04-14
 */
@Service
public class SysLabelTypeServiceImpl extends ServiceImpl<SysLabelTypeMapper, SysLabelType> implements ISysLabelTypeService {

    @Override
    public List<SysLabelType> queryList(SysLabelType sysLabelType) {
        LambdaQueryWrapper<SysLabelType> lqw = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(sysLabelType.getLabelTypeCode())) {
            lqw.eq(SysLabelType::getLabelTypeCode, sysLabelType.getLabelTypeCode());
        }
        if (StringUtils.isNotBlank(sysLabelType.getLabelTypeName())) {
            lqw.like(SysLabelType::getLabelTypeName, sysLabelType.getLabelTypeName());
        }
        return this.list(lqw);
    }

    @Cacheable(value = Constants.LABEL_TYPE_KEY, key = "#labelTypeId", unless = "#result == null ", cacheManager = "cacheManager1d")
    @Override
    public SysLabelType getLabelType(Long labelTypeId) {
        return this.getById(labelTypeId);
    }

    @CacheEvict(value = Constants.LABEL_TYPE_KEY, allEntries = true)
    @Override
    public boolean updateLabelType(SysLabelType sysLabelType) {
        return this.updateById(sysLabelType);
    }

    @CacheEvict(value = Constants.LABEL_TYPE_KEY, allEntries = true)
    @Override
    public boolean removeLabelTypes(List<Long> labelTypeIds) {
        return this.removeByIds(labelTypeIds);
    }
}
